
//
//  JumpTViewController.swift
//  新闻
//
//  Created by 芮京 on 2018/12/12.
//  Copyright © 2018 芮京. All rights reserved.
//

import UIKit

class JumpTViewController: UIViewController,UIScrollViewDelegate  {
    var name : String = ""
    var tdec : String = ""
    var arr:NSArray = []
    var scroll:UIScrollView?
    var img:UIImageView?
    var YeLable:UILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor=UIColor.black
        Scroll()
        TitleLable()
    }
    func Scroll() {
        //滚动式图
        scroll = UIScrollView(frame: CGRect(x: 0, y: 120, width: UIScreen.main.bounds.size.width, height: 250))
        self.view.addSubview(scroll!)
        scroll?.delegate = self
        scroll?.contentSize = CGSize(width: UIScreen.main.bounds.size.width * 3, height: 250)
        scroll?.bounces = false
        scroll?.isPagingEnabled = true
        //循环
        for i in 0..<arr.count {
            //图片
            img = UIImageView(frame: CGRect(x: i*Int(UIScreen.main.bounds.width), y: 0, width: Int(UIScreen.main.bounds.width), height: 220))
            let PImagV =  arr[i]
            let Purl = NSURL(string:PImagV as! String)
            let PData = NSData(contentsOf: Purl! as URL)
            img?.image = UIImage(data: PData as! Data)
            scroll?.addSubview(img!)
        }
    }
    func TitleLable() {
        //主标题
        let Zlabel = UILabel(frame: CGRect(x: 20, y: 360, width: UIScreen.main.bounds.width - 120, height: 20))
        self.view.addSubview(Zlabel)
        Zlabel.font = UIFont.systemFont(ofSize: 15)
        Zlabel.textColor = UIColor.white
        Zlabel.text = name
        //副标题
        let Flabel = UILabel(frame: CGRect(x: 20, y: 390, width: UIScreen.main.bounds.width - 100, height: 100))
        self.view.addSubview(Flabel)
        Flabel.font = UIFont.systemFont(ofSize: 12)
        Flabel.text = tdec
        Flabel.textColor = UIColor.white
        Flabel.numberOfLines = 0
        //页码
        YeLable = UILabel(frame: CGRect(x: UIScreen.main.bounds.width - 50, y: 355, width: 80, height: 30))
        self.view.addSubview(YeLable!)
        YeLable?.font = UIFont.systemFont(ofSize: 13)
        YeLable?.textColor = UIColor.white
        YeLable?.text = (NSString(format: "1/%ld", arr.count)) as String
    }
    //加一
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        YeLable?.text = (NSString(format: "%0.0f/%ld", (scrollView.contentOffset.x/UIScreen.main.bounds.width+1),arr.count)) as String
    }
    //隐藏导航条
    override func viewWillAppear(_ animated: Bool) {
        self.tabBarController?.tabBar.isHidden = true
    }
    override func viewWillDisappear(_ animated: Bool) {
        self.tabBarController?.tabBar.isHidden = false
    }
}
